
<hr/>
<p id="commentListp"></p>
<div id="commentList" >
{%if not helper:is_empty_table(comments) then%}
{% local pid=comments[1].pid %}
<div class="panel panel-info form-signin" style="margin-top: 5px;" >
{% for _,a in ipairs(comments) do%}
    {%if a.pid~=pid then%}
    </div>
    <div class="panel panel-info form-signin" style="margin-top: 5px;" >
    {% pid=a.pid %}
    {%end%}
    <div class="panel-body"{%if a.pid~=a.id then%}style="padding-left: 40px;" {%end%} >
        <p>{{a.name}}:{{a.updated_at}} {%if helper:intval(article.close_comment)>0 then%}<a href="javascript:repaly({{a.pid}},'{{a.name}}');">回复</a>{%end%}</p>
        <p>{{a.context}}</p>
    </div>
    {%end%}
</div>
{% if page then%}
{(page.html, {pageobj=page})}
{%end%}
</div>
{%end%}
{%if helper:intval(article.close_comment)>0 then%}
<script language="JavaScript">
<!--
  function repaly(pid,name){
    jQuery('#pid').val(pid);
    jQuery('#context').val("@("+name+"):");
    window.location=window.location.href.replace(/#.*$/,'')+"#comments";
  }
//-->
</script>
<form id='comments' action="{{helper:url('comments/save')}}" class="form-signin" method="post">
    <input type="hidden" name="aid" value="{{article.id}}">
    <input type="hidden" name="pid" id='pid' value="0">

    <input name="name" value="{{user_name}}" {%if user_name and user ~='' then%}readonly{%end%} class="input-block-level" type="text" class="input-block-level" placeholder="用户名">
    <p>
        <textarea id="context" name='context' class="input-block-level" placeholder="评论内容"></textarea>
    </p>
    <input type="submit" class="btn" value="提交评论"/>
</form>
<div id="myModal" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="exampleModalLabel">警告</h4>
            </div>
            <div class="modal-body">
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>
{-raw-}
<script language="JavaScript">
    <!--
    jQuery(function($){
        $('#comments').submit(function(){
            var $data=$(this).serialize();

            $.ajax({
                type: $(this).attr('method'),
                url:$(this).attr('action'),
                data: $data,
                dataType:'json',
                success: function(R){
                    if(R.code){
                        var msg="<div class=\"alert alert-danger\">";
                        msg+=" <ul>";
                        for(var i in R.data){                     
                            msg+="<li>"+R.data[i]+"</li>";
                        }
                        msg+="</ul>";
                        msg+=R.msg+"</div>";
                        $(".modal-body").html(msg);
                        $("#myModal").modal({'show':true,backdrop:false});
                    }else{
                        window.location.reload()
                    }
                }
            });
            return false;
        });
    });
    //-->
</script>
{-raw-}
{%end%}
